//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: CachedPersistent.cs
//
//  Description: A cached persistent object.
// 
//--------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace Chili.Opf3.Caching
{
	/// <summary>
	/// Represents a cached persistent object.
	/// </summary>
	internal sealed class CachedPersistent
	{
		private object _persistent;
		private DateTime _validUntil;
		private DateTime _createdOn = DateTime.Now;

		/// <summary>
		/// Creates a new instance of the <see cref="CachedPersistent">CachedPersistent Class</see>.
		/// </summary>
		/// <param name="persistent">The persistent that is cached.</param>
		/// <param name="validUntil">The time until the item is valid.</param>
		public CachedPersistent(object persistent, DateTime validUntil)
		{
			if (persistent == null)
				throw new ArgumentNullException("persistent");

			_persistent = persistent;
			_validUntil = validUntil;
		}

		/// <summary>
		/// Returns whether the cached persistent has expired.
		/// </summary>
		public bool Expired
		{
			get { return DateTime.Now > _validUntil; }
		}

		/// <summary>
		/// Gets or sets the date time until the item is valid.
		/// </summary>
		internal DateTime ValidUntil
		{
			get { return _validUntil; }
			set { _validUntil = value; }
		}

		/// <summary>
		/// Gets when the item was created.
		/// </summary>
		internal DateTime CreatedOn
		{
			get { return _createdOn; }
		}

		/// <summary>
		/// Returns the persistent.
		/// </summary>
		public object Persistent
		{
			get { return _persistent; }
		}
	}
}
